package com.itheima.health.controller;

import com.itheima.health.dto.OrderSettingDTO;
import com.itheima.health.entity.Result;
import com.itheima.health.service.OrderSettingService;
import com.itheima.health.vo.OrderSettingVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.text.ParseException;
import java.util.List;

/**
 * @author spt
 * @description 预约设置控制器
 * @date
 **/
@RestController
@RequestMapping("/ordersetting")
@Slf4j
@Api(tags = "后台预约设置接口")
public class OrderSettingController {
    @Autowired
    private OrderSettingService orderSettingService;

    /**
     * 查询预约情况
     * @param year
     * @param month
     * @return
     */
    @GetMapping("/getOrderSettingByMonth")
    @ApiOperation("后台预约模块-查询预约情况")
    public Result getOrderSettingByMonth(@RequestParam String year, @RequestParam String month){
        List<OrderSettingVO> list = orderSettingService.getOrderSettingByMonth(year, month);
        return Result.success(list);
    }

    /**
     * 上传文件
     */
    @PostMapping("/upload")
    @ApiOperation("后台预约模块-上传文件")
    public Result upload(MultipartFile excelFile){
        orderSettingService.upload(excelFile);
        return Result.success();
    }

    /**
     * 修改可预约数量
     * @param dto
     * @return
     * @throws ParseException
     */
    @PostMapping("/editNumberByDate")
    @ApiOperation("后台预约模块-修改可预约数量")
    public Result editNumberByDate(@RequestBody OrderSettingDTO dto) throws ParseException {
        orderSettingService.editNumberByDate(dto);
        return Result.success();
    }
}
